import requests

url = 'https://www.douguo.com/jingxuan/0'
head_data = {
    # 字典，需要有一个键值对
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36'
}
html = requests.get(url, headers=head_data)
# print(html.text)

# 数据解析
from lxml import etree

# html.text 需要加上.text 才是一个文本

html = etree.HTML(html.text)
# data = html.xpath('//*[@id="jxlist"]/li/div/a[1]/text()')
# print(data)

# 观看人数
# data = html.xpath('//span[@class="view"]/text()')
# print(data)

# 标题
# data = html.xpath('//a[@class="cookname text-lips"]/text()')
# print(data)

# author
data = html.xpath('//a[@class="author text-lips"]/img/@alt')
# data = [str(i).strip() for i in data if str(i).strip()]

# data1 = []
# for i in data:
#     if str(i).strip():
#         data1.append(str(i).strip())



print(data)


# 可以选择去复制xpath表达式使用，但是获取不到数据的时候
# 检查里面的数据是动态的，和响应体的数据是不一样的

# 获取不到数据，需要根据打印出来的源代码编写表达式

# https://www.douguo.com/jingxuan/0
# https://www.douguo.com/jingxuan/24
# https://www.douguo.com/jingxuan/48

